package com.gaiso.pushdemo;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;

import com.gaiso.gaisopush.data.PushConstant;

/**
 * Created by WangDongJie on 2017/4/20.
 */

public class PushNotification {

    private NotificationCompat.Builder mBuilder;
    private NotificationManagerCompat mManager;
    private Context mContext = ContextHolder.get();

    private PushNotification() {
        mBuilder = new NotificationCompat.Builder(mContext)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL);
        mManager = NotificationManagerCompat.from(mContext);
    }

    private static class SingletonHolder {
        private static final PushNotification INSTANCE = new PushNotification();
    }

    public static PushNotification getInstance() {
        return SingletonHolder.INSTANCE;
    }

    public void showMain(String msg) {
        Intent intent = new Intent(mContext, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
        mBuilder.setContentIntent(pendingIntent)
                .setContentText(msg)
                .setTicker("新的消息")
                .setContentTitle("Gaiso Push");
        mManager.notify(1, mBuilder.build());
    }
}
